package com.jrx.anytxn.param.transaction.job.billCompare.step;

import com.jrx.anytxn.param.mapper.ext.ExtTlBillTransCompareDetailMapper;
import com.jrx.anytxn.param.mapper.ext.ExtTlBillTransDetilMapper;
import com.jrx.anytxn.param.mapper.ext.ExtTlThirdBillDetailMapper;
import com.jrx.anytxn.param.transaction.job.billCompare.bean.BillDetilReadBean;
import com.jrx.anytxn.param.transaction.job.billCompare.bean.ThirdBillDetilReadBean;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.batch.item.ItemWriter;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Component
public class BillDetailWriter implements ItemWriter<ThirdBillDetilReadBean> {

    @Resource
    private ExtTlThirdBillDetailMapper extTlBillThirdDetailMapper;

    @Resource
    private ExtTlBillTransCompareDetailMapper extTlBillTransCompareDetailMapper;

    @Override
    public void write(List<? extends ThirdBillDetilReadBean> items) throws Exception {
        if (CollectionUtils.isNotEmpty(items)) {
            for (ThirdBillDetilReadBean bean : items) {
                if (CollectionUtils.isNotEmpty(bean.getTlBillTransDetilList())) {
                    extTlBillThirdDetailMapper.batchUpdate(bean.getTlBillTransDetilList());
                }
                if (CollectionUtils.isNotEmpty(bean.getTlBillTransCompareDetailList())) {
                    extTlBillTransCompareDetailMapper.insertbatch(bean.getTlBillTransCompareDetailList());
                }
            }
        }
    }
}
